package com.maxmlr.music.admin.controller;

import com.maxmlr.music.admin.entity.Menu;
import com.maxmlr.music.admin.param.TreeParam;
import com.maxmlr.music.admin.param.UserParam;
import com.maxmlr.music.admin.service.MenuService;
import com.maxmlr.music.common.bean.ResultBean;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ClassName LoginController
 * @Description TODO
 * @Author maxiao
 * @Date 2020/6/5 下午3:36
 * @Version V1.0
 */
@Controller
@Api(tags = "主页面跳转控制器")
public class AdmLoginController {

    @Autowired
    public MenuService menuService;

    @GetMapping({"/",""})
    public String index(){
        return "redirect:/index.html";
    }

    @GetMapping("/console")
    public String console(Model model) {
        List<TreeParam<Menu>> menus = menuService.listMenuTree(1);
        model.addAttribute("menus", menus);
//        model.addAttribute("name", getUser().getName());
//        FileDO fileDO = fileService.get(getUser().getPicId());
//        if (fileDO != null && fileDO.getUrl() != null) {
//            if (fileService.isExist(fileDO.getUrl())) {
//                model.addAttribute("picUrl", fileDO.getUrl());
//            } else {
//            }
//        } else {
//            model.addAttribute("picUrl", "/img/photo_s.jpg");
//        }
//        model.addAttribute("username", getUser().getUsername());
        return "index_v1";
    }

    @GetMapping("/login")
    public String login(){
        return "login";
    }

    @GetMapping("/main")
    public String main(){
        return "main";
    }

    @ResponseBody
    @PostMapping("/login")
    public ResultBean<Boolean> login(UserParam param){

        return ResultBean.ok(true);
    }

}
